<?php namespace Controller;

	abstract class Controller {
		
		protected $models = array();
		protected $params = array();
		protected $viewData = array();
		
		public function invokeAction($action, $params) {
			if(method_exists($this, $action)) {
				$this->params = $params;
				$this->$action()
					 ->_invokeView(substr(get_called_class(),11), $action, $this->viewData)
					 ->render();
			}
		}
		
		protected function _set($key,$value) {
			$this->viewData[$key] = $value;
		}
		
		protected function _invokeView($controller, $action, $data) {
			return new \View($controller, $action, $data);
		}

		protected function _loadModels() {
			$this->models = array_combine($this->models, array_map(function($mod) { $mod = 'Model\\'.$mod; return new $mod; }, $this->models));
			$db = new \Database;
			foreach ($this->models as $key => $value) {
				$value->setDB($db);
			}
		}
	}